/*
 * @Author: 蔡继周
 * @Date: 2021-11-13 16:47:57
 * @LastEditTime: 2021-11-13 17:06:42
 * @LastEditors: 蔡继周
 * @Description: I have to do something...
 * @FilePath: \blogAdmin\src\utils\loadingContent.js
 */
import { ElLoading } from 'element-plus'

// loading框设置局部刷新，且所有请求完成后关闭loading框
let loading
let needLoadingRequestCount = 0 // 声明一个对象用于存储请求个数
function startLoading(targetdq) {
    loading = ElLoading.service({
        lock: true,
        text: '努力加载中...',
        background: 'rgba(0, 0, 0, 0.7)',
        target: document.querySelector(targetdq), // 设置加载动画区域
    })
}

function endLoading() {
    loading.close()
}
export function showFullScreenLoading(targetdq) {
    if (needLoadingRequestCount === 0) {
        startLoading(targetdq)
    }
    needLoadingRequestCount++
}
export function hideFullScreenLoading() {
    if (needLoadingRequestCount <= 0) return
    needLoadingRequestCount--
    if (needLoadingRequestCount === 0) {
        endLoading()
    }
}

export default {
    showFullScreenLoading,
    hideFullScreenLoading
}